package com.hotel.controller;

import com.hotel.pojo.RoomType;
import com.hotel.service.RoomService;
import com.hotel.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author shkstart  房间类型控制器
 * @create 2021-06-28 1:33
 */
@Controller
public class RoomTypeController {

    @Autowired
    private RoomTypeService roomTypeService;

    //跳转到房间管理界面
    @RequestMapping("/skip/toRoomType")
    public String toRoom(Model model) {
        List<RoomType> list = roomTypeService.list(null);
        model.addAttribute("roomTypes",list);
        return "admin/views/roomType";
    }

    //跳转到房型添加页面
    @RequestMapping("/skip/toUpdateRoomType")
    public String toAddRoom(){
        return "admin/views/add/RoomTypeAdd";
    }

    //添加房型
    @RequestMapping("/addRoomType")
    public String AddRoom(RoomType roomType){
        boolean save = roomTypeService.save(roomType);
        System.out.println("房型添加结果为===>"  + save);
        return "redirect:/skip/toRoomType";
    }

    //跳转到房型修改界面
    @RequestMapping("/skip/toUpdateRoomType/{id}")
    public String toRoomTypeUpdate(@PathVariable("id")Integer id,Model model,RoomType roomType){
        RoomType byId = roomTypeService.getById(id);
        model.addAttribute("roomTypes",byId);
        return "admin/views/update/RoomTypeUpdate";
    }
    //修改房型
    @RequestMapping("/UpdateRoomType")
    public String UpdateRoomType(RoomType roomType){
        boolean b = roomTypeService.updateById(roomType);
        System.out.println("修改房型结果为===>" + b);
        return "redirect:/skip/toRoomType";
    }

    //删除房型
    @RequestMapping("/deletedRoomType/{id}")
    public String deletedRoomType(@PathVariable("id")Integer id){
        boolean b = roomTypeService.removeById(id);
        System.out.println("房型删除的结果为===>" + b);
        return "redirect:/skip/toRoomType";
    }

    //模糊查询房间类型信息
    @RequestMapping("/toSelectR")
    public String toSelect(String name,Model model){
        List<RoomType> roomTypes = roomTypeService.selectRoomType(name);
        System.out.println("进来了！");
        model.addAttribute("roomTypes",roomTypes);
        return "admin/views/roomType";
    }
}
